

wx.cloud.init({
  env: 'dongyingyin-3khfy'
})

const db = wx.cloud.database();
let text = ""
let imgUrls = ""
let abs = ""
Page({
  data: {
    ziyou:[],
    isShow: false,
    isShowbindtap: false,
    userput: [],
    title:"",
    imgUrls: [],
    abs:[{
      
      latitude: 23.633000,
      longitude: 113.678150,
    }
      


    ],
    imgUrls1: [ {
      _id	:	4,
      id: 3,
      latitude: 23.631000,
      longitude: 113.677450,
      iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
      width: 30,
      height: 30,
      callout: {
        content: " 教学楼1-4",
        padding: 10,
        display: 'ALWAYS',
        name: 'zhongdananfnag',
        textAlign: 'center',
        borderRadius: 10,
        color: '#ffffff',


        bgColor: '#ffe74b'
      }

    },],
    latitude1:'',
    longitude1:'',
    latitude:'',
    longitude:'',
    markers1: [
      
      {
      id: 1,
      latitude: 23.633100,
      longitude: 113.685116,
      iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
      width: 30,
      height: 30,
      scale: 17,
      name: 'zhongdananfnag',

    },

    {
      id: 3,
      latitude: 23.631000,
      longitude: 113.677450,
      iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
      width: 30,
      height: 30,
      callout: {
        content: " 教学楼1-4",
        padding: 10,
        display: 'ALWAYS',
        name: 'zhongdananfnag',
        textAlign: 'center',
        borderRadius: 10,
        color: '#ffffff',


        bgColor: '#ffe74b'
      }

    },

    {
      id: 4,
      latitude: 23.630900,
      longitude: 113.678550,
      iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
      width: 30,
      height: 30,
      callout: {
        content: " 实验楼1-3",
        padding: 10,
        display: 'ALWAYS',
        textAlign: 'center',
        color: '#ffffff',


        bgColor: '#ffe74b',
        borderRadius: 10

      }
    },
    {
      id: 5,
      latitude: 23.63360,
      longitude: 113.676800,
      iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
      width: 30,
      height: 30,
      callout: {
        content: "xxxx会议",
        padding: 10,
        display: 'ALWAYS',
        color: '#ffffff',
        bgColor: '#ffe74b',
        borderRadius: 10,
        textAlign: 'center',

      }

    },
    {
      _id: "dhjsbdhs",
      id: 6,
      latitude: 23.634550,
      longitude: 113.677840,
      iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
      width: 30,
      height: 30,
      callout: {
        content: " 行政楼a2",
        padding: 10,
        display: 'ALWAYS',
        borderRadius: 10,
        color: '#ffffff',
        bgColor: '#ffe74b',
        textAlign: 'center'
      }

    },
    {
      id: 7,
      latitude: 23.632700,
      longitude: 113.678740,
      iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
      width: 30,
      height: 30,
      callout: {
        content: " 图书馆",
        padding: 10,
        borderRadius: 10,
        color: '#ffffff',
        bgColor: '#ffe74b',
        display: 'ALWAYS',
        textAlign: 'center'
      }


    },

    {
      id: 8,
      latitude: 23.634700,
      longitude: 113.679340,
      iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
      width: 30,
      height: 30,
      callout: {
        content: "  中饭   （3、4）",
        padding: 10,
        display: 'ALWAYS',
        borderRadius: 10,
        color: '#ffffff',
        bgColor: '#ffe74b',
        textAlign: 'center'
      }


    },
    {
      id: 9,
      latitude: 23.632300,
      longitude: 113.674900,
      iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
      width: 30,
      height: 30,
      callout: {
        content: " 西操",
        padding: 10,
        borderRadius: 10,
        color: '#ffffff',
        bgColor: '#ffe74b',
        display: 'ALWAYS',
        textAlign: 'center'
      }


    },
    {
      id: 11,
      latitude: 23.63410,
      longitude: 113.682300,
      iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
      width: 30,
      height: 30,
      callout: {
        content: " 东饭",
        padding: 10,
        borderRadius: 10,
        color: '#ffffff',
        bgColor: '#ffe74b',
        display: 'ALWAYS',
        textAlign: 'center'
      }


    },
    {
      id: 12,
      latitude: 23.63390,
      longitude: 113.678540,
      iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
      width: 30,
      height: 30,
      callout: {
        content: " 教学楼5-7",
        padding: 10,
        borderRadius: 10,
        color: '#ffffff',
        bgColor: '#ffe74b',
        display: 'ALWAYS',
        textAlign: 'center'
      }


    },

    {
      id: 13,
      latitude: 23.63415,
      longitude: 113.680140,
      iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
      width: 30,
      height: 30,
      callout: {
        content: " 教学楼8-9",
        padding: 10,
        borderRadius: 10,
        color: '#ffffff',
        bgColor: '#ffe74b',
        display: 'ALWAYS',
        textAlign: 'center'
      }


    },
    {
      id: 14,
      latitude: 23.633300,
      longitude: 113.680140,
      iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
      width: 30,
      height: 30,
      callout: {
        content: " 教学楼10-11",
        padding: 10,
        borderRadius: 10,
        color: '#ffffff',
        bgColor: '#ffe74b',
        display: 'ALWAYS',
        textAlign: 'center'
      }


    },
    {
      id: 15,
      latitude: 23.632900,
      longitude: 113.680140,
      iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
      width: 30,
      height: 30,
      callout: {
        content: " 实验楼4",
        padding: 10,
        borderRadius: 10,
        color: '#ffffff',
        bgColor: '#ffe74b',
        display: 'ALWAYS',
        textAlign: 'center'
      }


    },
    {
      id: 17,
      latitude: 23.631500,
      longitude: 113.680140,
      iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
      width: 30,
      height: 30,
      callout: {
        content: " 综合楼",
        padding: 10,
        borderRadius: 10,
        color: '#ffffff',
        bgColor: '#ffe74b',
        display: 'ALWAYS',
        textAlign: 'center'
      }


    },
    {
      id: 16,
      latitude: 23.630500,
      longitude: 113.680350,
      iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
      width: 30,
      height: 30,
      callout: {
        content: " 商业中心",
        padding: 10,
        borderRadius: 10,
        color: '#ffffff',
        bgColor: '#ffe74b',
        display: 'ALWAYS',
        textAlign: 'center'
      }


    },
    {
      id: 17,
      latitude: 23.630780,
      longitude: 113.679650,
      iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
      width: 30,
      height: 30,
      callout: {
        content: " 快递中心",
        padding: 10,
        borderRadius: 10,
        color: '#ffffff',
        bgColor: '#ffe74b',
        display: 'ALWAYS',
        textAlign: 'center'
      }


    },
    {
      id: 10,
      latitude: 23.632300,
      longitude: 113.681240,
      iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
      width: 30,
      height: 30,
      callout: {
        content: "  东操",
        padding: 10,
        borderRadius: 10,
        color: '#ffffff',
        bgColor: '#ffe74b',
        display: 'ALWAYS',
        textAlign: 'center'
      }


    }
  ],
    tempMarkers1: [
      {
        id:0,
        latitude: 23.633711,
        longitude: 113.678424,
        iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
      //   width: 30,
      //   height: 30,
      content:"新冠疫苗活动"
      },
      {
        id:1,
        latitude:  23.632872,
        longitude:  113.679131,
        iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
      //   width: 30,
      //   height: 30,
      content:"校内游乐活动"
      },
     

    ],
    tempMarkers2: [
      {
        id:2,
        latitude: 23.633711,
        longitude: 113.678424,
        iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
        width: 30,
        height: 30,
      },
 

    ],
    curLatit:'',
    curLong:'',
    markers: [
      // {
      //   "id": 4,
      //   "latitude": 23.634303,
      //   "longitude": 113.677606,
      //   "iconPath": "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
      //   "width":30,
      //   "height":30,
      //   "callout": {
      //     "content": "新冠疫苗接种志愿者",
      //     "padding": 10,
      //     "borderRadius": 10,
      //     "color": "#ffffff",
      //     "bgColor": "#ffe74b",
      //     "display": "ALWAYS",
      //     "textAlign": "center"
      //   }
      // },

        // {
        //   // id:2,
        //   latitude: 23.633711,
        //   longitude: 113.678424,
        //   iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
        //   width: 30,
        //   height: 30,
        //  },

   

         {
                id: 3,
                latitude: 23.631000,
                longitude: 113.677450,
                iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
                width: 30,
                height: 30,
                callout: {
                  content: " 教学楼1-4",
                  padding: 10,
                  display: 'ALWAYS',
                  name: 'zhongdananfnag',
                  textAlign: 'center',
                  borderRadius: 10,
                  color: '#ffffff',
        
        
                  bgColor: '#ffe74b'
                }
        
              },
      ],
    url: "../../img/樱桃.png"
  },

  input1: function (m, index) {
   
    const {imgUrls1} =this.data
    console.log("之前",this.data.imgUrls1)

    const {curLatit}=this.data
    const{curLong}=this.data
    // var tempMarkers1 = [];
    // console.log(m)
    imgUrls1.forEach((m, index) => {
      var info = {
        id: '',
        iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
        // 标记点图片，常见有蓝色点你懂得 
        latitude: '', // 每一个被标点的纬度 
        longitude: '', // 每一个被标点的经度 
        width: 20, // 使用图标的宽度 
        height: 20, // 使用图标的高度 
        title: "", // 点击标记点显示的title 
        callout: {
          content: " ",
          padding: 10,
          display: 'ALWAYS',
          name: '',
          textAlign: 'center',
          borderRadius: 10,
          color: '#ffffff',
  
  
          bgColor: '#ffe74b'
        }


      };
      info.id = index;
      info.latitude = m.latitude;
      info.longitude = m.longitude;
      info.callout.content = m.callout.content;
      imgUrls1.push(info)
      this.setData({
        latitude: curLatit,
        longitude: curLong,
        markers: imgUrls1
      })
      console.log("之后",this.data.imgUrls1)

      console.log(this.data.latitude)
      console.log(this.data.longitude)
    })
  },


  input2: function (index) {
  //  获取markers数组的信息
    const {userput} =this.data
    const {title}=this.data
    // console.log("之前",this.data.imgUrls1)
  // 将data中点击的经纬度获取到函数之中
    const {curLatit}=this.data
    const{curLong}=this.data

    // var tempMarkers1 = [];
    // console.log(m)

  //  将经纬度添加到数组之中执行
  //  或者直接用函数来执行


    // 下一步就是开始循环markers数组的内容
    // 因为只有一个点，所以不需要循环，把foreach去除
    // imgUrls1.forEach((m, index) => {
      var info = {
        id: '',
        iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
        // 标记点图片，常见有蓝色点你懂得 
        latitude: '', // 每一个被标点的纬度 
        longitude: '', // 每一个被标点的经度 
        width: 20, // 使用图标的宽度 
        height: 20, // 使用图标的高度 
        title: "你成功了！", // 点击标记点显示的title 
        callout: {
          content: " ",
          padding: 10,
          display: 'ALWAYS',
          name: '',
          textAlign: 'center',
          borderRadius: 10,
          color: '#ffffff',
          bgColor: '#ffe74b'
        }


      };
      info.id = index;
      info.latitude = curLatit;
      info.longitude = curLong;
      info.callout.content= title;
      userput.push(info)
      this.setData({
        latitude: curLatit,
        longitude: curLong,
        markers: userput
      })
      // console.log("之后",this.data.imgUrls1)
      console.log("之后",this.data.markers)

   
      // 下面的小括号也要一起去除
    // })
  },






  input3: function (m, index) {
   
    const {abs} =this.data
    console.log("之前",this.data.abs)

    const {curLatit}=this.data
    const{curLong}=this.data
    // var tempMarkers1 = [];
    // console.log(m)
    abs.forEach((m, index) => {
      var info = {
        id: '',
        iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
        // 标记点图片，常见有蓝色点你懂得 
        latitude: '', // 每一个被标点的纬度 
        longitude: '', // 每一个被标点的经度 
        width: 20, // 使用图标的宽度 
        height: 20, // 使用图标的高度 
        title: "", // 点击标记点显示的title 
        callout: {
          content: " ",
          padding: 10,
          display: 'ALWAYS',
          name: '',
          textAlign: 'center',
          borderRadius: 10,
          color: '#ffffff',
          bgColor: '#ffe74b'
        }


      };
      info.id = index;
      info.latitude = m.latitude;
      info.longitude = m.longitude;
      // info.callout.content = m.callout.content;
      abs.push(info)
      this.setData({
        // latitude: curLatit,
        // longitude: curLong,
        markers:abs
      })
      console.log("之后",this.data.abs)

      console.log(this.data.latitude)
      console.log(this.data.longitude)
    })
  },

  
  input: function (index) {
  
    var tempMarkers = [];
    // res.forEach((m, index) => {


      var info = {
        id: 0,
        iconPath: "https://646f-dongyingyin-3khfy-1300530180.tcb.qcloud.la/dingdian.png?sign=8a288a66356343428164e98489926eb9&t=1620890661",
        // 标记点图片，常见有蓝色点你懂得 
        latitude: '23.634303', // 每一个被标点的纬度 
        longitude: '113.677606', // 每一个被标点的经度 
        width: 20, // 使用图标的宽度 
        height: 20, // 使用图标的高度 
        title: "新冠疫苗接种志愿者", // 点击标记点显示的title 
      };
      info.id = index;
      info.latitude =  '23.634303';
      // info.latitude = m.latitude;
      info.longitude = '113.677606';
      // info.longitude = m.longitude;
      // info.title = address;
      // info.title = m.address;
      tempMarkers.push(info)
      this.setData({
        latitude: 23.634303,
        // latitude: curLatit,
        longitude: 113.677606,
        // longitude: curLong,
        markers:[...this.data.markers, ...tempMarkers],
       
      })
      console.log(this.data.latitude)
      console.log(this.data.longitude)
    // })
  },


  onReady: function (options) {
    console.log("res",options)
    this.includePoints()
  },

  onShow: function (options) {
    console.log("res1",options)
    this.mapCtx = wx.createMapContext('map');
    this.setData({
      title: getApp().globalData.title
   
    })
  },
  tap: function () {
    wx.getLocation({
      type: 'gcj02',
      success: (res) => {
        const latitude = res.latitude
        const longitude = res.longitude
      }
    })
  },
  

  getdatapoint: function () {
    var that = this
    db.collection('swiper').get({
      success: function (res) {
        console.log(res)
       
        that.setData({
          abs:res.data[3]

        })
      
       

      }
    })
  },
  updatepoint: function () {
   





  },



  onLoad: function (options) {
    console.log("res2",options)
    var that = this
    db.collection('swiper').get({
      success: function (res) {
        console.log(res)
        console.log(res.data[1])
        console.log(res.data[0].imgUrls)
        that.setData({
          imgUrls2: res.data[0].imgUrls,
          markers: [...that.data.markers, ...res.data[1]],
          // markers: res.data[1],
          imgUrls: res.data[1]

        })
        console.log("chenggong", res.data[1].callout)

      }
    })
    // 上传数据库中的标点坐标
  
      




    // 获取数据库中的标点坐标
    // db.collection('markers').get().then(res => {
    //   console.log("asds", res.data[0].markers)
    //   that.setData({
    //     markers: res.data[0].markers
    //   })
    // })
  },


  markertranslation: function () {
    var that = this;
      // console.log("tianqi",that.dathata.geo_location)
      wx.request({
        url: 'https://apis.map.qq.com/tools/poimarker?type=0&marker=coord:23.630900,113.678550;title:中大南方;addr:广州市从化区温泉镇882号',
        
        // city:this.data.region[1],
        data:{
          
          referer:'mapin中南',

         
          key:'2OPBZ-2IFK6-KNQST-E7D2G-XHXLJ-RKBFC'
        },
        success:function(res){
          console.log(res);
        
        }
      })
    },


  setInput(e) {
    var inputVal = e.detail.value;
    this.setData({
      inputVal
    });
  },
  serchData() {
    this.qqmapsdk.search({
      keyword: this.data.inputVal,
      success: res => {
        var markers = this.data.markers;
        res.data.map((item, index) => {
          markers.push(this.setMark(item.location, index));
        })
        this.mapContext.moveToLocation();
        this.setData({
          markers
        });
      }
    });
  },
  setMark(location, index) {
    var temp = {
      iconPath: "../../img/樱桃.png",
      width: 30,
      height: 30,
      id: index,
      latitude: location.lat,

    };
    return temp;
  },

  includePoints: function () {
    this.mapCtx.includePoints({
      padding: [10],
      points: [{
        latitude: 23.636760,
        longitude: 113.674000
      }, {
        latitude: 23.629780,
        longitude: 113.685040,
      }]
    })
  },
  onChangeAddress: function () {
    var _page = this;
    wx.chooseLocation({
      success: function (res) {
        _page.setData({
          chooseAddress: res.name
        });
      },
      fail: function (err) {
        console.log(err)
      }
    });
  },


  reverseGeocoder(location) {
    this.qqmapsdk.reverseGeocoder({
      location,
      success: res => {
        console.log(res);
      }
    });
  },

  handleTextInput(e){
console.log(e)
this.setData({
  title:e.detail.value
})
  },

  inputpage(e){
  wx.navigateTo({
    url: '../index3/index3',
    
    success: (result) => {},
    fail: (res) => {},
    complete: (res) => {},
  })
    },


  bindtap2(e){
    console.log(e)
   this.setData({  
   })
    },

  bindtap(e){
  console.log(e.detail)
 this.setData({
  curLatit:e.detail.latitude,
  curLong:e.detail.longitude

 })

 

  },
  bindMakertap: function (event) {
    console.log(event, '11111');
    this.setData({
      isShowbindtap: true,
    })
  },

  

  bindtap3: function (event) {
    console.log(event, '11111');
    this.setData({
      isShowbindtap: false,
    })
  },

  bindMakertap1: function (event) {
    console.log(event, '11111');
    this.setData({
      isShow: true,
    })
  },

  

  bindtap31: function (event) {
    console.log(event, '11111');
    this.setData({
      isShow: false,
    })
  },

  clear: function (){
    this.setData({
      markers: [],
    })

  },

  ziyou: function (){
    var  that = this; 

      //  获取数据库中的标点坐标
    db.collection('ziyouMarker').get().then(res => {
      console.log("asds",res)
      console.log("文字信息",res.data[0].markers[0].callout.content)
      that.setData({
        markers: res.data[0].markers,
        ziyou:res.data[0].markers[0].callout.content
      })
    })

  },

  zhiyuan: function (){
    var  that = this; 

      //  获取数据库中的标点坐标
    db.collection('zhiyuanMarker').get().then(res => {
      console.log("asds",res)
      console.log("文字信息",res.data[0].markers)
        var src_list=res.data[0].markers
             var judge=res.data[0].markers["length"]
     console.log("length",judge)
            console.log("src_list",src_list)

    // src_list.forEach((item,judge)=>{
    //             var ziyou=Date.now()+"_"+judge;
    //   //           that.uploadImg(fileName,item)
    //           })


      that.setData({
        markers: res.data[0].markers,
        ziyou:src_list
      })
    })

  },

  jiangzuo: function (){
    var  that = this; 

      //  获取数据库中的标点坐标
    db.collection('jiangzuoMarker').get().then(res => {
      console.log("asds",res)
      that.setData({
        markers: res.data[0].markers,
        ziyou:res.data[0].markers[0].callout.content
      })
    })

  },

  shetuan: function (){
    var  that = this; 

      //  获取数据库中的标点坐标
    db.collection('shetuanMarker').get().then(res => {
      console.log("asds",res)
      that.setData({
        markers: res.data[0].markers,
        ziyou:res.data[0].markers[0].callout.content
      })
    })

  },



  clearup: function (){
    wx.removeStorageSync("markers"),
      // wx.removeStorageSync("markers")
    
      this.setData({
        // markers: wx.clearStorageSync("markers"),
        markers: []
      })
     
   

  },

  ckMap(e){
    var temp = {
      iconPath: "/assets/img/local.png",
      id: 0,
      width: 25,
      height: 25,
      ...e.detail
    }
    var markers = this.data.markers;
    markers.push(temp);
    this.setData({
      markers
    }, () => {
      var data = {
        ...e.detail
      };
      this.mapCtx.moveToLocation(data)
    })
  }
})

